package cn.lg.soar.system.biz.modules.auth.model;

import cn.lg.soar.common.data.tree.ITreeResult;
import cn.lg.soar.system.api.enums.RoleTypeEnum;
import cn.lg.soar.system.biz.modules.auth.entity.Role;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.List;

/**
 * 菜单树形数据
 * @author luguoxiang
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@Getter
@Setter
public class RoleTree implements ITreeResult<RoleTree>, Serializable {

    private Long id;

    private RoleTypeEnum type;

    private String code;

    private String name;

    private List<RoleTree> children;

    @Override
    public List<RoleTree> getChildren() {
        return children;
    }

    @Override
    public void setChildren(List<RoleTree> children) {
        this.children = children;
    }

    public RoleTree() {
    }

    public RoleTree(Role role) {
        if (role == null) {
            return;
        }
        this.id = role.getId();
        this.type = role.getType();
        this.code = role.getCode();
        this.name = role.getName();
    }

    public static RoleTree from(Role role) {
        return new RoleTree(role);
    }

}
